<template>
  <el-dialog :visible="combineLockVisible" width="80%" :title="dialogTitle" :before-close="closeDialog">
    <el-form :inline="true"
             :rules="rules"
             ref="form"
             :model="formData"
             label-width="80px"
             size="small"

             >
      <el-row>
        <el-form-item label="交易日期：">
          <el-date-picker
              style="max-width: 325px;"
              v-model="searchParams.jyrq"
              type="daterange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="changeJyrqDate"
              value-format="yyyy-MM-dd"
              :default-time="['00:00:00', '23:59:59']">
          </el-date-picker>
          </el-form-item>
          <el-form-item label="业务编号：">
            <el-input

                v-model="searchParams.ywbh"
            ></el-input>
          </el-form-item>
          <el-form-item label="投保单号：">
            <el-input

                v-model="searchParams.tbdh"
            ></el-input>
          </el-form-item>

            <el-button type="danger" size="mini" @click="getInvoice" :loading="loading">查询</el-button>
            <el-button type="primary" size="mini" @click="onResize" >
              重置
            </el-button>
      </el-row>

      <tableList
          :showIndex="false"
          :data="listDetails"
          border
          maxHeight="500"
          heightMin="280"
          :loading="loading"
          :keySet="keySet"
          :autoHeight="true"
          :tableData="listDetails"
          :paginationShow="true"
          :pageNumber="pages.current"
          :pageSize="pages.size"
          :total="pages.total"
          :radioSelect="true"
          @radioHandleCurrentChange="radioHandleCurrentChange"
          @handleSizeChange="handleSizeChange"
          @rowClick="rowClick"
          @handleCurrentChange="handleCurrentChange"
      >
      </tableList>
    </el-form>
    <el-row style="margin-top: 0px">
      <div class="centered-dialog">
        <el-button type="primary" size="mini" @click="closeDialog">取消</el-button>
        <el-button type="primary" size="mini" @click="confirmSubmit()" :loading="loading">
          确定
        </el-button>
      </div>
    </el-row>



  </el-dialog>
</template>

<script>
import DictSelect from "@/views/invoiceTemplate/components/DictSelect/DictSelect.vue";
import tableList from "@/components/tableList/index.vue";
import mixinTable from "@/mixin/mtable";
import {combineLockQuery, combineLockConfirm} from '@/api/minusFlowManage.js'

export default {

  data() {
    return {
      combineLockVisible: false,
      dialogTitle: '正数流水查询',
      loading: false,
      listDetails: [],
      formData: {


      },
      rules: {
        jyrqq: [
          {
            required: true,
            message: '请选择交易开始日期',
            trigger: 'change',
          },
        ],
        jyrqz: [
          {
            required: true,
            message: '请选择交易截止日期',
            trigger: 'change',
          },
        ],

      },
      keySet: [

        {
          label: '业务编号',
          englishName: 'ywbh',
          width: '150px'
        },
        {
          label: '投保人',
          englishName: 'kfhm',
          width: '150px'
        },
        {
          label: '投保单号',
          englishName: 'tbdh',
          width: '150px'
        },

        {
          label: '交易金额',
          englishName: 'jyrmbje',
          width: 150
        },

        {
          label: '税率',
          englishName: 'slv',
          width: 150
        },
        {
          label: '险种简称',
          englishName: 'xzjc',
          width: '150px'
        },
        {
          label: '交易日期',
          englishName: 'jyrq',
          width: '150px'
        },
        {
          label: '流水状态',
          englishName: 'lszt',
          width: '145px',
          formatter: (value) => {
            if (value == '1') {
              return '未开票'
            } else if (value == '2') {
              return '部分开票'
            } else if (value == '3') {
              return '已开票'
            } else if (value == '0') {
              return '已锁定'
            }
          }
        },

      ]
    };
  },
  components: {
    tableList,
    DictSelect,

  },
  mixins: [mixinTable],
  methods: {
    changeJyrqDate(date) {
      if (date === null) {
        this.searchParams.jyrqq = ''
        this.searchParams.jyrqz = ''
      } else {
        this.searchParams.jyrqq = this.searchParams.jyrq[0]
        this.searchParams.jyrqz = this.searchParams.jyrq[1]

      }
    },
    //关闭窗口
    closeDialog() {
      this.combineLockVisible = false;
      this.listDetails = [];
      this.formData = {}
      this.$refs.form.resetFields();
      this.searchParams = {
        input1: '',
        input2: '',
        input3: '',
        select1: '',
        select2: '',
        select3: '',
        date1: '',
        date2: '',
      }
    },
    // 确认提交
    async confirmSubmit() {
      // 选择的正数流水主键  ycl_rdid;
      // 正数流水主键，rdid
      // id负数流水管理表主键id
      let params = {
        id: this.formData.id,
        ycl_rdid: this.selectRow.rdid,
        rdid: this.formData.rdid,
      }
      let {data, code, message} = await combineLockConfirm(
          params
      );
      if (code == 200) {
        this.loading = false

      }
    },
    //根据交易日期，投保单号，业务编号查询数据
    async getInvoice(){
      if(!this.searchParams.jyrqq){
        this.$message.error('请选择交易开始日期')
        return
      }
      if(!this.searchParams.jyrqz){
        this.$message.error('请选择交易截止日期')
        return
      }
      this.pages.current = 1
      this.loading = true;
      let params = {
        tbdh: this.searchParams.tbdh,
        ywbh: this.searchParams.ywbh,
        jyrqq:this.searchParams.jyrqq,
        jyrqz:this.searchParams.jyrqz,
        //jyjg:this.searchParams.jyjg,
        pageNo: this.pages.current,
        pageSize: this.pages.size,
      }
      let {data, code, message} = await combineLockQuery(
          params
      );
      if (code == 200) {
        this.loading = false
        this.listDetails = data.records.map(item => {
          return {
            ...item
          }
        })
        this.pages.total = data.total
        this.pages.current = data.current
        this.pages.size = data.size
      }
    },
    onResize() {
      this.$refs.form.resetFields();
      this.searchParams = {
        input1: '',
        input2: '',
        input3: '',
        select1: '',
        select2: '',
        select3: '',
        date1: '',
        date2: '',
      }
    },
    rowClick(row) {
      this.selectRow = row
    }
    ,
    radioHandleCurrentChange(row) {
      this.selectRow = row
    }
    ,
    handleCurrentChange(val) {
      this.pages.current = val
      this.getInvoice()
    }
    ,
    handleSizeChange(val) {
      this.pages.size = val
      this.getInvoice()
    }
  },
};
</script>

<style  lang = "scss" scoped>
@import '@/style/variables.scss';
.centered-dialog {
  display: flex;
  align-items: center;
  justify-content: center;
}

.el-form-item{
  margin-left: 30px;
  .el-input{
    width: 180px;
  }
}

</style>